import java.util.Scanner;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/10/14 23:12
 * 统计回文
 * 连续最大和
 */
public class Day5 {
    public static void main1(String[] args) {
        // 统计回文
        Scanner scanner = new Scanner(System.in);
        String targetStr = scanner.nextLine();
        String checkStr = scanner.nextLine();
        int count=0;
        for (int i = 0; i <= targetStr.length(); i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < i; j++) {
                sb.append(targetStr.toCharArray()[j]);
            }
            sb.append(checkStr);
            for (int j = i; j < targetStr.length(); j++) {
                sb.append(targetStr.toCharArray()[j]);
            }
            if(isHuiWen(sb.toString())){
                count ++;
            }
        }
        System.out.println(count);
    }
    public static boolean isHuiWen(String str){
        char[] ch = str.toCharArray();
        int right = ch.length-1;
        int left = 0;
        while ((left < right) && ch[left]==ch[right] ){
            left++;
            right--;
        }
        if (left>=right){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int num = scanner.nextInt();
            int[] nums = new int[num];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }

            int max = nums[0];
            int sum = nums[0];
            for (int i = 1; i < nums.length; i++) {
                if(sum>=0){
                    sum+=nums[i];
                }else {
                    sum = nums[i];
                }
                if (sum>max){
                    max = sum;
                }
            }
            System.out.println(max);
        }
    }
}
